/*================================================================
*   文件名称：main.cpp
*   创 建 者：yang qiang
*   创建日期：2021年02月27日
*   描    述：
*   Copyright (C) 2021 All rights reserved.
*
* ================================================================*/


#include <iostream>
#include <vector>
using namespace std;


int get_min_time(int *time, int n){
    int res = 101;
    int k;
    for(int i = 0; i < n; i++){
        if(res > time[i]){
            k = i;
            res = time[i];
        }
    }

    time[k] = 102;
    return res;
}

int get_max_time(int *time, int n){
    int res = -1;
    for(int i = 0; i < n; i++){
        res = max(res, time[i]);
    }

    return res;
}
//多cpu多道批处理模拟
int processingTime(int m, int n, int *time){
    if(m >= n){
        return get_max_time(time, n);
    }

    int cpu[m][2] = {0};
    int end = 0;
    int count = n;

    int all_time = 0;
    while(!end){
        for(int i = 0; i < m && count > 0; i++){
            if(cpu[i][0] == 0){
                cpu[i][0] = 1;
                cpu[i][1] = get_min_time(time, n);
                count--;
            }
        }

        int left_time = 101;
        for(int i = 0; i < m; i++){
            if(cpu[i][0] == 1){ //在运行
                left_time = min(left_time, cpu[i][1]);
            }
        }

        for(int i = 0; i < m; i++){
            if(cpu[i][0] == 1){ //在运行
                cpu[i][1] -= left_time;
                if(cpu[i][1] == 0){
                    cpu[i][0] = 0;
                }
            }
        }

        all_time += left_time;

        int idle_cpu = 0;
        for(int i = 0; i < m; i++){
            if(cpu[i][0] == 0){
                idle_cpu++;
            }
        }

        //cout << idle_cpu<<endl;
        if(idle_cpu == m){
            end = 1;
            break;
        }
    }

    return all_time;
}


int main(){
    int m, n;
    cin>>m>>n;
    int time[n];
    for(int i = 0; i < n; i++){
        cin >> time[i];
    }

    cout << processingTime(m ,n, time) << endl;

    return 0;
}
